<?php

namespace App\Http\Middleware;

use Closure;

class Login
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if( $request->ajax()){

            //若果没有检测到用户登陆，提示无权限
            if (!Auth::check()) return response('UserNotLogin',403);

        }else{

            if (!Auth::check()){
                return redirect('/#login');

            }

        }
        return $next($request);
    }
}
